package com.zhk.ScriptManagement.controller;

import com.alibaba.fastjson.JSONObject;
import com.zhk.ScriptManagement.constant.ShiroConstant;
import com.zhk.ScriptManagement.entity.User;
import com.zhk.ScriptManagement.service.UserService;
import com.zhk.ScriptManagement.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;

/**
 * @author zhk
 * @description 用户controller
 * @date 2021-02-19 17:36:04
 **/
@RestController
@RequestMapping("auth")
public class LoginController {

    @Autowired
    private UserService userService;

    /**
     * 登录
     */
    @PostMapping("/login")
    public Result login(@RequestBody User user)  {
      if(!Optional.ofNullable(user).isPresent()){
          return Result.error(CodeMsg.PARAMETER_ISNULL,"参数不能为空");
      }
        return userService.login(user);
    }

    /**
     * 退出
     */
    @PostMapping("/logout")
    public Result logout() {
        return userService.logout();
    }

}
